Skip to content

PYTHON-5846 Consolidate CMAP, heartbeat, and SDAM telemetry into _telemetry.py - #14

Closed
blink1073 wants to merge 9 commits into
masterfrom
PYTHON-5846
Closed

PYTHON-5846 Consolidate CMAP, heartbeat, and SDAM telemetry into _telemetry.py#14
blink1073 wants to merge 9 commits into
masterfrom
PYTHON-5846

Conversation

@blink1073

Copy link
Copy Markdown
Owner

[PYTHON-5846]

Changes in this PR

Building on PYTHON-5745 (which consolidated command telemetry), this PR adds three new classes to pymongo/_telemetry.py to eliminate the repetitive if enabled_for_cmap / if _LOGGER.isEnabledFor(logging.DEBUG) boilerplate that was duplicated across pool.py, monitor.py, topology.py, and server.py.

  • _CmapTelemetry: Handles all 11 CMAP events (pool created/ready/cleared/closed, connection created/ready/closed, checkout started/succeeded/failed, checked-in). Stored on Pool and shared with AsyncConnection. Replaces enabled_for_cmap, enabled_for_logging, and repeated _client_id log fields.

  • _HeartbeatTelemetry: Handles the 3 heartbeat lifecycle events. Uses apm_started() before connection checkout (no conn_id yet) and log_started() after checkout. Stored as self._current_hb on Monitor to bridge the _check_once/_check_server split.

  • _SdamTelemetry: Handles topology and server events with queue-based APM publishing. Used by Topology (topology opened/closed/description changed, server opened/closed/description changed) and Server (server closed).

Net change: -404 lines across 9 files (async + sync via synchro).

Test Plan

  • just typing-mypy passes with no issues across all 3 mypy invocations (153, 242, and 2 source files).
  • ruff check passes on all changed files.
  • Pre-commit hooks pass (synchro, ruff, ruff-format).
  • Existing CMAP, SDAM, and heartbeat monitoring tests cover the consolidated code paths; no behavior was changed.

Checklist

Checklist for Author

  • Did you update the changelog (if necessary)?
  • Is there test coverage?
  • Is any followup work tracked in a JIRA ticket? If so, add link(s).

sleepyStick and others added 9 commits June 23, 2026 07:53
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Steven Silvester <steve.silvester@mongodb.com>
Co-authored-by: Noah Stapp <noah@noahstapp.com>
…ongodb#2884)

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Iris <58442094+sleepyStick@users.noreply.github.com>
Co-authored-by: Cloud User <ec2-user@ip-10-128-193-139.ec2.internal>
Co-authored-by: Iris <58442094+sleepyStick@users.noreply.github.com>
Co-authored-by: Iris <iris.ho@mongodb.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…emetry.py

Add _CmapTelemetry, _HeartbeatTelemetry, and _SdamTelemetry classes to
eliminate the repetitive if-enabled_for_cmap / if-logger.isEnabledFor
boilerplate spread across pool.py, monitor.py, topology.py, and server.py.
@blink1073 blink1073 closed this Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants